package patrol.mobile.com.mobilepatrol.adapter;

import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.bridge.BridgeListActivity;
import patrol.mobile.com.mobilepatrol.bean.Qiaoliang;

/**
 * Created by long on 2016/8/24.
 * 桥梁巡查列表
 */
public class BridgeTrackListAdapter extends BaseQuickAdapter<Qiaoliang> {
    private BridgeListActivity context;
    private List<String> qlcodes = new ArrayList<>();
    public BridgeTrackListAdapter(BridgeListActivity context, List<Qiaoliang> data) {
        super(context, data);
        this.context =  context;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item1;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final Qiaoliang item) {
        holder.setText(R.id.tv1, item.name);
        holder.setText(R.id.tv2, item.roadcode+"("+item.pos+")");
        CheckBox cb = holder.getView(R.id.cb);
        cb.setChecked(item.isCheck);

        cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    qlcodes.add(item.qlcode);
                    context.specialUpdate(0,qlcodes.size(),item.qlcode);
                }else{
                    qlcodes.remove(item.qlcode);
                    context.specialUpdate(1,qlcodes.size(),item.qlcode);
                }
            }
        });
        if (item.isUp){
            holder.setVisible(R.id.iv_up,true);
        }else{
            holder.setVisible(R.id.iv_up,false);
        }

    }
    public List<String> getQlcodes(){
        return qlcodes;
    }

}
